package com.yinhe.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.enums.BusinessType;
import com.yinhe.system.domain.YhContractFile;
import com.yinhe.system.service.IYhContractFileService;
import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.common.core.page.TableDataInfo;

/**
 * 合同资料Controller
 * 
 * @author yinhe
 * @date 2022-07-20
 */
@RestController
@RequestMapping("/system/file")
public class YhContractFileController extends BaseController
{
    @Autowired
    private IYhContractFileService yhContractFileService;

    /**
     * 查询合同资料列表
     */
    @PreAuthorize("@ss.hasPermi('system:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(YhContractFile yhContractFile)
    {
        startPage();
        List<YhContractFile> list = yhContractFileService.selectYhContractFileList(yhContractFile);
        return getDataTable(list);
    }

    /**
     * 导出合同资料列表
     */
    @PreAuthorize("@ss.hasPermi('system:file:export')")
    @Log(title = "合同资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhContractFile yhContractFile)
    {
        List<YhContractFile> list = yhContractFileService.selectYhContractFileList(yhContractFile);
        ExcelUtil<YhContractFile> util = new ExcelUtil<YhContractFile>(YhContractFile.class);
        util.exportExcel(response, list, "合同资料数据");
    }

    /**
     * 获取合同资料详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:file:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yhContractFileService.selectYhContractFileById(id));
    }

    /**
     * 新增合同资料
     */
    @PreAuthorize("@ss.hasPermi('system:file:add')")
    @Log(title = "合同资料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YhContractFile yhContractFile)
    {
        return toAjax(yhContractFileService.insertYhContractFile(yhContractFile));
    }

    /**
     * 修改合同资料
     */
    @PreAuthorize("@ss.hasPermi('system:file:edit')")
    @Log(title = "合同资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YhContractFile yhContractFile)
    {
        return toAjax(yhContractFileService.updateYhContractFile(yhContractFile));
    }

    /**
     * 删除合同资料
     */
    @PreAuthorize("@ss.hasPermi('system:file:remove')")
    @Log(title = "合同资料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yhContractFileService.deleteYhContractFileByIds(ids));
    }
}
